﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Gencode.PrsCommon.Data.Person
{
	public class Person : PersonBase
	{
		public Person(int prsID)
		{
			PrsID = prsID;
			Init(prsID);
		}

		public Person() { }

		#region Implementation
        internal virtual void Init(int prsID)
        {
			DataView dv = Gencode.Common.SQL.SimpleQuerry.ExecuteForDataView("select Vorname, Nachname, Strasse, Strassennr, PLZ, Ort, Email, TelnrP, TelnrN, Postfach from Person where PrsId = " + PrsID);
            if (dv.Count > 0)
            {
                Vorname = dv[0].Row[0].ToString();
                Nachname = dv[0].Row[1].ToString();
                Strasse = dv[0].Row[2].ToString();
                StrassenNummer = dv[0].Row[3].ToString();
                PLZ = dv[0].Row[4].ToString();
                Ort = dv[0].Row[5].ToString();
				Email = dv[0].Row["Email"].ToString();
				TelefonPrivat = dv[0].Row["TelnrP"].ToString();
				Natel = dv[0].Row["TelnrN"].ToString();
				Postfach = dv[0].Row["Postfach"].ToString();
            }
			dv.Dispose();
        }
		#endregion

		#region Properties

		public string Strasse
		{
			get;
			protected set;
		}

		public string StrassenNummer
		{
			get;
			protected set;
		}

		public string PLZ
		{
			get;
			protected set;
		}

		public string Ort
		{
			get;
			protected set;
		}

		public string TelefonPrivat
		{
			get;
			private set;
		}

		public string Natel
		{
			get;
			private set;
		}

		public string Email
		{
			get;
			private set;
		}

		public string Postfach
		{
			get;
			private set;
		}

		/// <summary>
		/// Anstellungid wird immer aktuell aus DB genommen
		/// </summary>
		public int AnstellungID
		{
			get
			{
				if (PrsID > 0)
				{
					DataView dv = Gencode.Common.SQL.SimpleQuerry.ExecuteForDataView("select AnstellungID from PersonAnstellung where Von <= GETDATE() and Bis >= GETDATE() and PrsID = " + PrsID);
					if (dv.Count > 0)
						return int.Parse(dv[0].Row[0].ToString());

					return 0;
				}
				return 0;
			}
		}

		#endregion
	}
}
